package com.violet.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "dto.verify")
public class DTOVerifyProperties {

    // 可以忽略的字段
    private String[] ignoreFields = {};

    private Name name = new Name(2, 10);
    private Description description = new Description(2, 40);
    private Phone phone = new Phone();

    // 判断当前字段是否可以忽略
    public boolean isIgnore(String field) {
        for (String ignoreField : ignoreFields) {
            if (ignoreField.equals(field)) return true;
        }
        return false;
    }

    // 验证名称
    public record Name(Integer min, Integer max) {
        public Name {
            if (min == null) min = 2;
            if (max == null) max = 10;
        }
    }

    // 验证描述
    public record Description(Integer min, Integer max) {
        public Description {
            if (min == null) min = 2;
            if (max == null) max = 40;
        }
    }

    // 手机号
    public record Phone() { }
}
